$('.checkbox input,.popup-vote input').iCheck({
	checkboxClass: 'icheckbox_square-green',
	radioClass: 'iradio_square-green'
});

//右侧菜单
$('.sidebar-info').on('click','a',function(){
	$('.sidebar-info .active').removeClass('active');
	$(this).addClass('active');
});
//创建空间
$('.btn-create-space').on('click',function(event){
	$('.popup-createspace').show();
	return false;
})

//点赞
$('a.zhan').click(function(){
    if($(this).hasClass('like')){//未赞    	   	
      	var obj = $(this),
      		Num = parseInt(obj.find('span').text());
            Num--;
            obj.find('span').text(Num);
            obj.find('em').text('赞');
            $(this).removeClass('like');   
    }else{//已赞
       var left = parseInt($(this).position().left) + 10,
            top = parseInt($(this).position().top) - 14,
            obj = $(this);
            
             obj.find('em').text('取消赞');	
             var Num = parseInt(obj.find('span').text());
             Num++;
             obj.find('span').text(Num);
         $(this).append('<div class="zhans"><b>+1<\/b></\div>');
         $('.zhans').css({
             'position': 'absolute',
             'z-index': '1',
             'color': '#f90',
             'left': left + 'px',
             'top': top + 'px'
         }).animate({
             top: top - 12,
             left: left + 0,
             opacity:0
         }, 'slow', function () {
             $(this).remove(); 
         });
        
        $(this).addClass('like')
        return false;        
    }
})
//发送范围
$('#range-select,#range-select2').multiselect({
	 //maxHeight: 220,
	 buttonClass: 'btn btn-range',
	 nonSelectedText: '发送范围',
	 enableFiltering: true,
	 filterPlaceholder: '搜索',
	 dropRight: true
});
//显示人物卡片
$('.post-item').on('mouseenter','img.media-object ',function(){
	$(this).closest('.post-item').find('.profile-card').fadeIn(100)
})
$('.post-item .profile-card').mouseleave(function(){
	$(this).hide()
});
$('.post-item').on('mouseleave','.panel-body',function(){
	$('.profile-card').hide()
});
//$('.topic').readmore();
$('.topic').each(function(){
	var h = $(this).height();
	//alert(h);
	if(h>=260){
		$(this).next('a.readmore').show();
	}
});
$('.topic2').each(function(){
	var h = $(this).height();
	//alert(h);
	if(h>=44){
		$(this).next('a.readmore').show();
	}
});

//输入框激活 按钮出现
$('.post-item-reply').on('focus','input[type="text"]',function(e){
	$('.post-item-reply-addons').hide();
	$(this).next('.post-item-reply-addons').show();
	//return false;
	e.stopPropagation();
	
});
$(document).on("click",function(e){ 
	var target = $(e.target); 
	if(target.closest(".post-item-reply").length == 0){ 
		$(".post-item-reply-addons").hide(); 
		$('.post-item-reply .addimg-method').hide();
		$('.btn-addimg').removeClass('active')
	} 
	if(target.closest(".quickreply").length == 0){ 
		$('.quickreply').remove()
	} 
}); 



//点击回复
$('.post-item').on('click','a.btn-comment',function(e){
	var username = $(this).siblings('b').text();
	var replyBox = '<div class=\"quickreply\">'
		+'<div class=\"textarea textarea-quickreply\" contenteditable=\"true\" tabindex=\"-1\">'
		+'<button onclick=\"return false;\" tabindex=\"-1\" contenteditable=\"false\">回复'+ username + '</button>&nbsp;'
		+'</div>'
		+'<div class=\"onlyreply-addons clearfix\">'
		+'<div class=\"pull-left\">'														      		
		+'<a href=\"javascript:;\" class=\"btn-face\"><i class=\"gicon gicon-face2\"></i></a>'
		+'<a href=\"javascript:;\" class=\"btn-addimg\"><i class=\"gicon gicon-img\"></i></a>'
		+'</div>'
		+'<div class=\"pull-right\">'
		+'<a href=\"javasript:;\" class=\"btn g-btn-blue btn-quickreply\">回复</a>'
		+'</div>'
		+'</div>'
		+'<div class=\"addimg-method\">'
		+'<p class=\"clearfix\">'
		+'<a href=\"javascript:;\" class=\"localimg fl\">'
		+'<input type=\"file\" class=\"btn-localimg\" multiple accept=\"image/*\">'
		+'</a>'
		+'<i class=\"gicon gicon-line2 fl\"></i>'
		+'<a href=\"javascript:;\" class=\"ucimg\">文件中心</a>'
		+'<a href=\"javascript:;\" class=\"pull-right btn-addimg-cancel\"><i class=\"gicon gicon-cancel\"></i></a>'
		+'</p>'
		+'</div>'
		+'</div>';
		
		$('.quickreply').hide();
		$(this).closest('.media-body').append(replyBox);
		
		$('.btn-localimg').fileinput({
//			language:'zh',
//			uploadUrl: "/upload/",
//		    allowedFileExtensions: ["jpg", "png", "gif"],
//		    showUpload: false,
//			showCaption: false,
//			showRemove:false,
//			resizeImage: true,
//			browseClass: "",
//			maxFileCount: 8,
//			dropZoneEnabled:false
		});

		$(this).closest('.media-body').find('.textarea-quickreply').focus();	
		return false;
})

$('.post-comment-list').on('click','.btn-addimg',function(){
	$(this).closest('.onlyreply-addons').next('.addimg-method').show();
})

//发表处 添加图片 addimg-method
$('.info-post').on('click','.btn-addimg',function(){
	$(this).addClass('active');
	$(this).closest('.info-post').next('.addimg-method').show();
	return false;
})
$('.info-mainarea').on('click','.btn-addimg-cancel',function(){
	$('.addimg-method').hide();
	$('.btn-addimg').removeClass('active');
})

$('.post-item-reply').on('click','.btn-addimg',function(){
	$(this).addClass('active');
	$(this).closest('.post-item-reply-addons').next('.addimg-method').show();
})
//image-input 
$('.btn-localimg').fileinput({
	language:'zh',
	uploadUrl: "/upload/",
    allowedFileExtensions: ["jpg", "png", "gif"],
    showUpload: false,
    showRemove:false,
	showCaption: false,
	resizeImage: true,
	browseClass: "btnUploadImg",
	maxFileCount: 8,
	validateInitialCount: true,	
	dropZoneEnabled:false	
});

//删除上传图片
$('.info-mainarea').on('click','.preview-del',function(e){
	$(this).closest('.file-preview-frame').remove();
	return false;
})




//与我相关-动态显示删除评论回复

$('.post-relateme').on('mouseenter','.post-item-content',function(){
	var trashHtml = '<i class="gicon gicon-trash btn-relate-del"></i>';
	$(this).append(trashHtml);
});

$('.post-relateme').on('mouseleave','.post-item-content',function(){
	$(this).find('.btn-relate-del').remove();
});


//按钮取消-弹窗关闭
$('.popup').on('click','.btn-popup-cancel',function(){
	$(this).closest('.popup').hide();
})
//弹窗-删除动态
$('.post-relateme').on('click','.btn-relate-del',function(){
	$('.popup-delRelate').show();
})

//弹窗-删除帖子
$('.post-item').on('click','.btn-del-post',function(){
	$('.popup-del-post').show();t
})
$('.popup-del-post').on('click','.g-btn-gray',function(){
	$(this).closest('.popup-del-post').hide();
})

//弹窗-添加成员
$('.info-user-list').on('click','.btn-add-user',function(){
	$('.popup-adduser').show();
})

//弹窗-投票
$('.btn-addvote').on('click',function(){
	$(this).addClass('active');
	$('.popup-vote').show();
});
$('.popup-vote').on('click','.popup-close',function(){
	$('.btn-addvote').removeClass('active');
})
//select
 $('.selectpicker').selectpicker();
//datetime picker
$('.hasdate').datetimepicker({
	lang:'ch',
	format:'Y-m-d H:i',
	yearStart:2015,
	yearEnd:2050
});

//del option
$('.popup-vote form').on('click','.btn-option-del',function(){
	$(this).closest('.form-group').remove();
})
//add option
function getNum(text){
	var value = text.replace(/[^0-9]/ig,""); 
	return value;
}
$('.popup-vote form').on('click','.btn-add-option',function(){
	var num = $(this).closest('.form-group').prev('.form-group').find('.control-label').text();
			num = parseInt(getNum(num))+1;	
	var html ='<div class=\"form-group\">'+
				    '<label class=\"col-sm-2 control-label\">选项'+ num + '</label>'+
				    '<div class=\"col-sm-10\">'+
						'<div class=\"input-group\">'+	        
					  '     <input type=\"text\" class=\"form-control input-white\">'+
					  '      <span class=\"input-group-addon btn-option-del\"><i class=\"gicon gicon-close\"></i></span>'+
					  '</div>'+				      
				    '</div>'+
				  	'</div>';				  	
	$(this).closest('.form-group').before(html);
});

//弹窗-长文章 
$('.btn-addarticle').on('click',function(){
	$(this).addClass('active');
	$('.popup-addarticle').show();
});
$('.popup-addarticle').on('click','.popup-close',function(){
	$('.btn-addarticle').removeClass('active');
})
$('.summernote').summernote({
	height: 300, 
	minHeight: null,             
	maxHeight: null,
	focus: true 	
});
  
//multi-select
$('#modal-range-select').multiselect({
	 //maxHeight: 220,
	 buttonClass: 'btn btn-range',
	 nonSelectedText: '发送范围',
	 enableFiltering: true,
	 filterPlaceholder: '搜索',
	 dropRight: true
});
//转发
$('.info-mainarea').on('click','.btn-zhuanfa',function(){
	$('.popup-zhuangfa').show();
});
function detailmainH(){
	var eleH1,eleH2,eleH3,eleH4,eleH5,targetH;
	eleH1 = $(window).height();	

	targetH = eleH1-51;
	$('.detail-main').css({'min-height':targetH+'px'});	
	$('.detail-sidebar').css({'min-height':targetH+'px'});	
}	


function configMainH(){
	var eleH1,eleH2,eleH3,eleH4,eleH5,targetH;
	eleH1 = $(window).height();	
	
	eleH2 = $('.solo-header').outerHeight();
	targetH = eleH1- eleH2 - 51-45;
	$('.config-main').css({'height':targetH+'px'});	

}

function listgroupsidebarH(){
	var eleH1,eleH2,eleH3,eleH4,eleH5,targetH;
	eleH1 = $('.sidebar').height();	
	targetH = eleH1-24;
	$('.sidebar-info>dl').css({'height':targetH+'px'});	

}

$(function(){
    listgroupsidebarH();
    configMainH();
    detailmainH();
    //$(window).on('resize',listgroupsidebarH,configMainH);
    $(window).on('resize',function(){
    	listgroupsidebarH();
    	configMainH();
    	detailmainH();
    })
});


//fileupload-1103
var imgMsgFilesTooMany = '<i class="glyphicon glyphicon-info-sign"></i> 图片上传数量已达上限';
var imgMsgSelected = '图片：({n}/8)';
$(".upfile-img-local").fileinputLocales.zh.msgFilesTooMany = imgMsgFilesTooMany;
$(".upfile-img-local").fileinputLocales.zh.msgSelected = imgMsgSelected;

$(".upfile-img").fileinput({
	language:'zh',
	uploadUrl: "/upload/",
    maxFileCount: 8,
    validateInitialCount: true,
    dropZoneEnabled:false,
    overwriteInitial: false,    
    showUpload: false,
	showRemove:false,
	//showCaption: false,
    allowedFileExtensions: ["jpg", "png", "gif"]
});


var videoMsgFilesTooMany = '<i class="glyphicon glyphicon-info-sign"></i> 只能添加一个视频，请删除后再添加';
$(".upfile-video-local").fileinputLocales.zh.msgFilesTooMany = videoMsgFilesTooMany;

$(".upfile-video-local").fileinput({
	language:'zh',
	uploadUrl: "/upload/",
    maxFileCount: 1,
    validateInitialCount: true,
    dropZoneEnabled:false,
    overwriteInitial: false,    
    showUpload: false,
	showRemove:false,
	//showCaption: false,
    allowedFileExtensions: ["mp4","wmv"]
});

var audioMsgFilesTooMany = '<i class="glyphicon glyphicon-info-sign"></i> 音乐上传数量已达上限';
var audioMsgSelected = '音乐：({n}/6)';
$(".upfile-audio-local").fileinputLocales.zh.msgFilesTooMany = audioMsgFilesTooMany;
$(".upfile-audio-local").fileinputLocales.zh.msgSelected = audioMsgSelected;
$(".upfile-audio-local").fileinput({
	language:'zh',
	uploadUrl: "/upload/",
    maxFileCount: 6,
    validateInitialCount: true,
    dropZoneEnabled:false,
    overwriteInitial: false,    
    showUpload: false,
	showRemove:false,
	//showCaption: false,
    allowedFileExtensions: ["mp3"],
    previewFileType:'img'
});

function tri(){
	$('.hastri').removeClass('hastri')
	$('.comtri:not(.hide)').eq(0).addClass('hastri');
}

$('#b1').on('click',function(){	
	//$(this).siblings('.upfile-img-block').removeClass('hide');
	//$(this).siblings('.upfile-img-block').find('.upfile-img').click();
	$('.upfile-img-block').removeClass('hide');
	$('.upfile-img-block').find('.upfile-img').click();
	tri()
})
//视频本地
$('#vLocal').on('click',function(){	
	//$(this).closest('.upfile-div').find('.upfile-video-block').removeClass('hide')
	//$(this).closest('.upfile-div').find('.upfile-video-local').click();
	$('.upfile-video-block').removeClass('hide');
	$('.upfile-video-local').click();
	tri()
});
//视频在线
$('#vOnline').on('click',function(){	
	$('.upfile-video-online').removeClass('hide');
	tri()
});
$('.btn-plus-confirm').on('click',function(){
	var url = $(this).closest('.urlInput').find('input').val();
	if(url!=''){
		var videoHtml = '<video width="180px" height="120px" controls>'+
	       '<source src="' + url + '" type="video/mp4">'+
	       '<div class="file-preview-other">'+
		   '<span class="file-icon-4x"><i class="glyphicon glyphicon-file"></i></span>'+
		   '</div>'+
	   	   '</video>';   	      	   
   	   
		$(this).closest('.urlInput').addClass('hide');
		$(this).closest('.urlInput').siblings('.file-preview-thumbnails').removeClass('hide');
		$(this).closest('.upfile-video-online').find('.file-preview-frame').prepend(videoHtml);
	}

});
$('.upfile-video-online').on('click','.fileinput-remove',function(){
	$(this).closest('.upfile-video-online').addClass('hide');
	$(this).closest('.upfile-video-online').find('.urlInput').removeClass('hide');
	$(this).closest('.upfile-video-online').find('.urlInput input').val('');	
	$(this).closest('.upfile-video-online').find('.file-preview-frame').find('video').remove();
	$(this).closest('.upfile-video-online').find('.file-preview-thumbnails').addClass('hide');	
});
$('.upfile-video-online').on('click','.kv-file-remove',function(){
	$(this).closest('.file-preview-thumbnails').addClass('hide');
})
//音频本地
$('#aLocal').on('click',function(){	
	//$(this).closest('.upfile-div').find('.upfile-audio-block').removeClass('hide');
	//$(this).closest('.upfile-div').find('.upfile-audio-local').click();
	$('.upfile-audio-block').removeClass('hide');
	$('.upfile-audio-local').click();
	tri()
});

$('.comtri').on('click','.fileinput-remove',function(){
	$(this).closest('.comtri').addClass('hide')
	tri();
})
